package com.choichumgming.rentcat.web.controller;

import com.choichumgming.rentcat.common.api.CommonResult;
import com.choichumgming.rentcat.model.PmsProduct;
import com.choichumgming.rentcat.model.PmsProductCategory;
import com.choichumgming.rentcat.service.PmsCatagoryService;
import com.choichumgming.rentcat.service.PmsProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName PmsCatagoryController
 * @Description : 管理商品类别功能
 * @Author : choichumgming
 * @Date : 1/3/2020 11:57
 */
@Controller
@Api(tags = "PmsCatagoryController", description = "商品类别管理")
@RequestMapping("/category")
public class PmsCatagoryController {
    @Autowired
    PmsCatagoryService pmsCatagoryService;
    @Autowired
    PmsProductService pmsProductService;
    @ApiOperation("获取商品类别")
    @RequestMapping(value = "/", method = RequestMethod.GET)
    @ResponseBody
    CommonResult getAllCatagory(){
        List<PmsProductCategory> list = pmsCatagoryService.getAll();
        return CommonResult.success(list);
    }


    @ApiOperation("根据类别id查询商品")
    @RequestMapping(value = "/list/{categoryId}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<List<PmsProduct>> getProductByCategoryId(@PathVariable(value = "categoryId") Long categoryId,
                                                                 @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                                 @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        List<PmsProduct> productList = pmsProductService.getProductListByCategoryId(categoryId, pageNum, pageSize);

        return CommonResult.success(productList);
    }
}
